/*
  ID: nemokin1
  PROG: holstein
  LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef long double ld;
const int INF = 1000000000;

void add(VI& a, VI b)
{
    for(int i = 0; i < a.size(); i++){
	a[i] = a[i] + b[i];
    }
    return;
}

bool compare(VI a, VI b)
{
    for(int i = 0; i < a.size(); i++){
	if(a[i] < b[i]) return false;
    }
    return true;
}

int main() {
    freopen("holstein.in","r",stdin);freopen("holstein.out","w",stdout);
    int N;
    cin >> N;
    VI orig;
    for(int i = 0; i < N; i++){
	int tt;
	cin >> tt;
	orig.push_back(tt);
    }
    int q;
    vector<vector<int> > vita;
        
    cin >> q;
    for(int i = 0; i < q; i++){
	VI temp;
	for(int j = 0; j < N; j++){
	    int tt;
	    cin >> tt;
	    temp.push_back(tt);
	}
	vita.push_back(temp);
    }

    VI ret;
    
    for(int i = 1; i < (1<<q); i++){
	VI cp(N,0);
	for(int j = 0; j < q; j++){
	    if(i & (1 << j)){
		add(cp,vita[j]);
	    }
	}
//	debugv(cp);
	if(compare(cp,orig) == true) ret.push_back(i);
    }
    
    VI sin;
    int minz = 100;
    
    for(int i = 0; i < ret.size(); i++){
	if(__builtin_popcount(ret[i]) < minz){
	    sin.clear();
	    sin.push_back(ret[i]);
	    minz = __builtin_popcount(ret[i]);
	}
	else if(__builtin_popcount(ret[i]) == minz){
	    sin.push_back(ret[i]);
	}
    }
//    debugv(sin);
    sort(sin.begin(),sin.end());
    cout << minz << " ";
    int cos = sin[0];
    VI log;
    
    while(cos){
	int cd = cos&(~(cos-1));
	log.push_back( __builtin_ctz(cos)+1);
	cos = cos & (~cd);
    }

    for(int i = 0; i < log.size()-1; i++) cout << log[i] <<" ";
    cout << log[log.size()-1] <<endl;
    
    exit(0);
}
